﻿using HBKY.Shop.Common;
using HBKY.Shop.Common.Helper;
using InitQ;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace HBKY.Shop.Extensions.ServiceExtensions
{
    /// <summary>
    /// Redis 消息队列 启动服务
    /// </summary>
    public static class RedisInitMqSetup
    {
        public static void AddRedisInitMqSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            if (Appsettings.Option("Middleware", "RedisMq", "Enabled").ObjToBool())
            {
                var masterConfig = Appsettings.Option("ConnectionStrings", "RedisConnection", "RedisConnectionString");
                var sentinels = Appsettings.OptionArray("ConnectionStrings", "RedisConnection", "Sentinels");
                services.AddInitQ(m =>
                {
                    //时间间隔
                    m.SuspendTime = 50;
                    //redis服务器地址
                    m.IsSentinel = true;
                    m.SentinelOptions = new SentinelOptions() { Sentinels = sentinels, MasterConfig = masterConfig };
                    //对应的订阅者类，需要new一个实例对象，当然你也可以传参，比如日志对象
                    m.ListSubscribe = new List<Type>() {
                       
                    };
                    //显示日志
                    m.ShowLog = false;
                });
            }
        }
    }
}
